package com.mtzqc.helper

import android.content.Context
import android.content.SharedPreferences
import com.mtzqc.SupportApp

object PrivacyHelper {
    private var sp: SharedPreferences? = null
    private const val SP_NAME = "SpPrivacy"
    private val AGREE_KEY = "privacy"
    private fun getSp(context: Context): SharedPreferences {
        if (null == sp) {
            sp = context.applicationContext.getSharedPreferences(SP_NAME, Context.MODE_PRIVATE)
        }
        return sp!!
    }

    var agreeValue: Boolean? = null

    fun isAgree(context: Context = SupportApp.app()): Boolean {
        if (null == agreeValue) {
            agreeValue = getSp(context).getBoolean(AGREE_KEY, false)
        }
        return agreeValue!!
    }

    fun updateAgree() {
        getSp(SupportApp.app()).edit().putBoolean(AGREE_KEY, true).apply()
    }
}